#include<typeinfo>
#include<unistd.h>
#include<iostream>
#include<fstream>
#include<vector>
#include"../Decision.h"
#include"../DecisionMaking.hpp"
using namespace std;
using namespace RobotDec;
using namespace Dec;
void Sleep(int x)
{
    sleep(x/1000);
}
void test1()
{
    unordered_map<size_t, Identity> v;
   Identity i1;
   Rember r1;
   bitset<64> b1;
   b1.set(1);

   r1._name = 6;
   r1._action = ACTION_BUMPFISR;
   r1._emotion = EMO_ANGRY;
   r1._attitude = ATT_NORMAL;
   r1._model = MOD_NORMAL;
   r1._probability = 0.6;

   i1._name = r1._name;
   // i1._history = r1;
   i1._mode = r1._model;
   i1._actions = b1;

   v.insert({i1._name, i1});
   v.insert({ 20, Identity() });

  // StoreIdentity::WriteIdentityToFile(v, DATA_PATH);

   unordered_map<size_t, Identity> v2;
 //  StoreIdentity::ReadIdentitiesFromFile(&v2, DATA_PATH);
   for (auto& i : v2)
   {
       cout << i.first << ":" << i.second._name << endl;
   }
   int h = 10;
   while(true)
   {

   }
}
void test2()
{
    unordered_map<size_t, Identity> v;
       Identity i1;
       Rember r1;
       bitset<64> b1;
       b1.set(11);
       b1.set(1+BIT_OFFSET);
       r1._name = 6;
       r1._action = ACTION_BUMPFISR;
       r1._emotion = EMO_LOVE;
       r1._attitude = ATT_NORMAL;
       r1._model = MOD_FRIENDLY;
       r1._probability = 1;
       i1._name = r1._name;
       // i1._history = r1;
       i1._mode = 10;
       i1._actions = b1;
       i1._mrem.Push(r1);
       v.insert({i1._name, i1});
     //  StoreIdentity::WriteIdentityToFile(v, DATA_PATH);

     /*  unordered_map<size_t, Identity> v2;
       StoreIdentity::ReadIdentitiesFromFile(&v2, DATA_PATH);
       for (auto& i : v2)
       {
           cout << i.first << ":" << i.second._name << endl;
       }*/
    RobotDec::Desion my_desion;
    int i = 1;
    cout << "1------------------" << endl << endl;

    //第一个人的记忆交互
    while (i <= 200)
    {
        Response result;
        RobotDec::Input inp;
        inp._name = 1;
        inp._voice = 11;
        inp._pose = 1;
        /* cin >> inp._name >> inp._voice >> inp._pose;
         cin.ignore(256, '\n');*/
        bool res = my_desion.Start(inp, &result);
        if (!res)
        {
            result._expression += " 忽略，没有决策!";
        }
        else {
            result._expression += " 决策成功!";
        }
        std::string str = result.Serialize();
        cout << "第 " << i++ << " 次：" << str << endl;
        Sleep(1000);
    }
}
void test3()
{
    RobotDec::Desion my_desion;
    int i = 1;
    cout << "1------------------" << endl << endl;

    //第一个人的记忆交互
    while (i <= 200)
    {
        Response result;
        RobotDec::Input inp;
        inp._name = 1;
        inp._voice = 11;
        inp._pose = 1;
        /* cin >> inp._name >> inp._voice >> inp._pose;
         cin.ignore(256, '\n');*/
        bool res = my_desion.Start(inp, &result);
        if (!res)
        {
            result._expression += " 忽略，没有决策!";
        }
        else {
            result._expression += " 决策成功!";
        }
        std::string str = result.Serialize();
        cout << "第 " << i++ << " 次：" << str << endl;
        //Sleep(1000);
    }
    //2
    cout << "2------------------" << endl << endl;

    i = 1;
    while (i <= 200)
    {
        Response result;
        RobotDec::Input inp;
        inp._name = 2;
        inp._voice = 7;
        inp._pose = 0;
        /* cin >> inp._name >> inp._voice >> inp._pose;
         cin.ignore(256, '\n');*/
        bool res = my_desion.Start(inp, &result);
        if (!res)
        {
            result._expression += " 忽略，没有决策!";
        }
        else {
            result._expression += " 决策成功!";
        }
        std::string str = result.Serialize();
        cout << "第 " << i++ << " 次：" << str << endl;
        //Sleep(1000);
    }
    //3
    i = 1;
    cout << "3------------------" << endl << endl;
    while (i <= 200)
    {
        Response result;
        RobotDec::Input inp;
        inp._name = 3;
        inp._voice = 0;
        inp._pose = 10;
        /* cin >> inp._name >> inp._voice >> inp._pose;
         cin.ignore(256, '\n');*/
        bool res = my_desion.Start(inp, &result);
        if (!res)
        {
            result._expression += " 忽略，没有决策!";
        }
        else {
            result._expression += " 决策成功!";
        }
        std::string str = result.Serialize();
        cout << "第 " << i++ << " 次：" << str << endl;
        //Sleep(1000);
    }
    //4
    cout << "4------------------" << endl << endl;

    i = 1;
    while (i <= 200)
    {
        Response result;
        RobotDec::Input inp;
        inp._name = 4;
        inp._voice = 0;
        inp._pose = 12;
        /* cin >> inp._name >> inp._voice >> inp._pose;
         cin.ignore(256, '\n');*/
        bool res = my_desion.Start(inp, &result);
        if (!res)
        {
            result._expression += " 忽略，没有决策!";
        }
        else {
            result._expression += " 决策成功!";
        }
        std::string str = result.Serialize();
        cout << "第 " << i++ << " 次：" << str << endl;
        //Sleep(1000);
    }
    //5
    i = 1;
    cout << "5------------------" << endl << endl;

    while (i <= 200)
    {
        Response result;
        RobotDec::Input inp;
        inp._name = 5;
        inp._voice = 0;
        inp._pose = 12;
        /* cin >> inp._name >> inp._voice >> inp._pose;
         cin.ignore(256, '\n');*/
        bool res = my_desion.Start(inp, &result);
        if (!res)
        {
            result._expression += " 忽略，没有决策!";
        }
        else {
            result._expression += " 决策成功!";
        }
        std::string str = result.Serialize();
        cout << "第 " << i++ << " 次：" << str << endl;
        //Sleep(1000);
    }
    //6
    i = 1;
    while (i <= 100)
    {
        Response result;
        RobotDec::Input inp;
        inp._name = 6;
        inp._voice = 11;
        inp._pose = 0;
        /* cin >> inp._name >> inp._voice >> inp._pose;
         cin.ignore(256, '\n');*/
        bool res = my_desion.Start(inp, &result);
        if (!res)
        {
            result._expression += " 忽略，没有决策!";
        }
        else {
            result._expression += " 决策成功!";
        }
        std::string str = result.Serialize();
        cout << "第 " << i++ << " 次：" << str << endl;
        //Sleep(1000);
    }
}

// 测试短期不交互的遗忘
void test5()
{
    RobotDec::Desion my_desion;
    int i = 1;
    while (i <= 50)
    {
        Response result;
        RobotDec::Input inp;
        inp._name = 6;
        inp._voice = 11;
        inp._pose = 1;
        /* cin >> inp._name >> inp._voice >> inp._pose;
         cin.ignore(256, '\n');*/
        bool res = my_desion.Start(inp, &result);
        if (!res)
        {
            result._expression += " 忽略，没有决策!\n";
        }
        else {
            result._expression += " 决策成功!\n";
        }
        std::string str = result.Serialize();
        cout << "第 " << i++ << " 次：" << str << endl;
        //Sleep(1000);
    }
    i = 1;
    while (i <= 30)
    {
        Response result;
        RobotDec::Input inp;
        inp._name = 8;
        inp._voice = 11;
        inp._pose = 1;
        /* cin >> inp._name >> inp._voice >> inp._pose;
         cin.ignore(256, '\n');*/
        bool res = my_desion.Start(inp, &result);
        if (!res)
        {
            result._expression += " 忽略，没有决策!\n";
        }
        else {
            result._expression += " 决策成功!\n";
        }
        std::string str = result.Serialize();
        cout << "第 " << i++ << " 次：" << str << endl;
        Sleep(1000);
    }
    i = 1;
    while (i <= 200)
    {
        Response result;
        RobotDec::Input inp;
        inp._name = 255;
        inp._voice = 0;
        inp._pose = 0;
        /* cin >> inp._name >> inp._voice >> inp._pose;
         cin.ignore(256, '\n');*/
        bool res = my_desion.Start(inp, &result);
        if (!res)
        {
            result._expression += " 忽略，没有决策!\n";
        }
        else {
            result._expression += " 决策成功!\n";
        }
        std::string str = result.Serialize();
        cout << "第 " << i++ << " 次：" << str << endl;
        Sleep(2000);
    }
    i = 1;
    while (i <= 30)
    {
        Response result;
        RobotDec::Input inp;
        inp._name = 7;
        inp._voice = 11;
        inp._pose = 1;
        /* cin >> inp._name >> inp._voice >> inp._pose;
         cin.ignore(256, '\n');*/
        bool res = my_desion.Start(inp, &result);
        if (!res)
        {
            result._expression += " 忽略，没有决策!\n";
        }
        else {
            result._expression += " 决策成功!\n";
        }
        std::string str = result.Serialize();
        cout << "第 " << i++ << " 次：" << str << endl;
        Sleep(1000);
    }
    int a = 10;
}
void test6()
{
    RobotDec::Desion my_desion;
    int i = 1;
    int j = 1;
    while (j <=10)
    {
        cout << "----------第" << j << "人交互--------" << endl;
        while (i <= 200)
        {

            Response result;
            RobotDec::Input inp;
            inp._name = j;
            inp._voice = 0;
            inp._pose = 12;
            /* cin >> inp._name >> inp._voice >> inp._pose;
             cin.ignore(256, '\n');*/
            bool res = my_desion.Start(inp, &result);
            if (!res)
            {
                result._expression += " 忽略，没有决策!\n";
            }
            else {
                result._expression += " 决策成功!\n";
            }
            std::string str = result.Serialize();
            cout << "第 " << i++ << " 次：" << str << endl;
            //i++;

        }
        i = 1;
        j++;
    }
    Response result;
    RobotDec::Input inp;
    inp._name = 255;
    bool res = my_desion.Start(inp, &result);
    cout << result.Serialize() << endl;
    for (auto e = my_desion._identitys.begin();e!= my_desion._identitys.end();e++)
    {
        cout << "身份：" << e->second._name<< "  个性：" << e->second._mode << " " << endl;
    }
   
}
static const string f = "./test.rem";
void test7()
{
    //1.
    unordered_map<size_t, size_t> ud1;
    ud1.insert({ 1,1 });
    ud1.insert({ 789,200 });
    bitset<64> bs1;
    bs1.set(35);

    Identity i1;
    i1._name = 3;
    i1._actions = bs1;
    i1._order_count = ud1;
    //2.
       /* unordered_map<size_t, size_t> ud2;
        ud2.insert({ 3,5 });
        ud2.insert({ 222,144 });
        bitset<64> bs2;
        bs2.set(35);

        Identity i2;
        i2._name = 4;
        i2._actions = bs2;
        i2._order_count = ud2;*/

        //
    unordered_map<size_t, Identity> tmp;
    tmp.insert({ 1,i1 });
    /* tmp.insert({ 2,i2 });*/
    cout << &tmp << endl;
    for (auto e : tmp)
    {
        cout << &e << ": " << "key:" << e.first << " val:" << e.second._name << endl;
        for (auto i : e.second._order_count)
        {
            cout << i.first << "---" << i.second << endl;
        }
    }
    StoreIdentity::WriteIdentityToFile(tmp, f);
}

void test8()
{
    unordered_map<size_t, Identity> tmp;
    Identity i1;
    cout << typeid(i1._order_count).name() << endl;;
    cout << &tmp << endl;
    tmp = StoreIdentity::ReadIdentitiesFromFile(f);
    cout << &tmp << endl;
    for (auto e : tmp)
    {
        cout << &e << ": " << "key:" << e.first << " val:" << e.second._name << endl;
    }
}


 static vector<string> EMO = {"正常(短)","期待","惊呆","困惑","开心","冷漠","喜欢","悲伤","无语","打招呼","生气","疼痛","疲惫","委屈","享受","眩晕","正常(长)","未知"};
 static vector<string> ACTION = {"正常站立","走","跑","左转","右转","停止","俯卧撑","蹲起","扭屁股","打招呼","滑步","跳舞","mini步","太空步","趴下","坐下"
,"握手","碰拳","左边转圈","右边转圈","后退","靠近","转身"};
 static vector<string> VOICE = {"无","左转","右转","前进","后退","趴下","坐下","跳舞","俯卧撑","打招呼","跳跃","碰拳","握手","正确","错误","太空步","停止","转圈","靠近","跑","滑步","向后转","退出"};
 static vector<string> POSE = { "无","碰拳","生气","开心","错误","坐下","打招呼","夸赞","枪击","再见","鄙视","赞同","激怒","同意","喜欢","跳舞" };
/// <summary>
/// 测试机器人是否具备个性
/// </summary>
/// 
bool ExecutionProbability(double x)
{
    double y = x * 100;
    std::random_device rd; // 用于生成随机种子
    std::mt19937 gen(rd()); // 使用随机种子初始化随机数生成器
    std::uniform_int_distribution<int> dis(0, 99); // 定义一个均匀分布的整数随机数分布器，范围为0到99
    int number = dis(gen);
    if (number < y)
    {
        return true;
    }
    return false;
}
//传入一段区间的起始位置，随机生成区间内的一个数
int RangProbability(int x,int y)
{
    std::random_device rd; // 用于生成随机种子
    std::mt19937 gen(rd()); // 使用随机种子初始化随机数生成器
    std::uniform_int_distribution<int> dis(x,y); // 定义一个均匀分布的整数随机数分布器，范围为0到99
    int number = dis(gen);
    return number;
}
void test4()
{
    fstream file;
    file.open("per_test_2.txt", ios::app);
    file << "实验结果如下：" << endl;
    RobotDec::Desion my_desion1;//友好交互
    RobotDec::Desion my_desion2;//非友好交互
    file << "------------------" << endl << endl;
    int j = 0;
    while (j < 20)
    {
        int i = 1;
        //第一个人的记忆交互
        file << "-------------身份：" << j+1 << "-------------" << endl;
        file << "-------------------------------------------" << endl;
        if (j < 10)
        {

            while (i <= 200)
            {
                Response result;
                RobotDec::Input inp;
                inp._name = j+1;
                inp._voice = ExecutionProbability(0.5)?11:12;//碰拳
                inp._pose = 0;
                /* cin >> inp._name >> inp._voice >> inp._pose;
                 cin.ignore(256, '\n');*/
                bool res = my_desion1.Start(inp, &result);
                if (!res)
                {
                    result._expression += " 忽略，没有决策!";
                }
                else {
                    result._expression += " 决策成功!";
                }
                std::string str = result.Serialize();
                file << "机器人1号:";
                file << "第 " << i++ << " 次：" << str << endl;
                //Sleep(1000);
            }
        }
        else
        {
            while (i <= 200)
            {
                Response result;
                RobotDec::Input inp;
                inp._name = j+1;
                inp._voice = 0;
                inp._pose = ExecutionProbability(0.5) ? 10 : 12; //激怒
                /* cin >> inp._name >> inp._voice >> inp._pose;
                 cin.ignore(256, '\n');*/
                bool res = my_desion2.Start(inp, &result);
                if (!res)
                {
                    result._expression += " 忽略，没有决策!";
                }
                else {
                    result._expression += " 决策成功!";
                }
                std::string str = result.Serialize();
                file << "机器人2号:";
                file << "第 " << i++ << " 次：" << str << endl;
                //Sleep(1000);
            }
        }
        j++;
    }
    Response result;
    RobotDec::Input inp;
    inp._name = 255;
    bool res1 = my_desion1.Start(inp, &result);
    bool res2 = my_desion2.Start(inp, &result);

    file << "机器人1号对每个交互者的个性："<<endl;
    for (auto& e : my_desion1._identitys)
    {
        file << "身份：" << e.second._name << " 个性：" << e.second._mode << " "<<endl;
    }
    file << "机器人2号对每个交互者的个性：" << endl;
    for (auto& e : my_desion2._identitys)
    {
        file << "身份：" << e.second._name << " 个性：" << e.second._mode << " " << endl;
    }

    file << "##############################################################" << endl;
    file << "######################友好状态################################" << endl;
    file << "##############################################################" << endl;
    int i = 1;
    //经过10个人的共计10*200次的友好交互后的机器人与新的交互者进行握手动作
    while (i <= 100)
    {
       
        Response result;
        RobotDec::Input inp;
        inp._name = j+1;
        inp._voice = 12;//握手
        inp._pose = 0;
        /* cin >> inp._name >> inp._voice >> inp._pose;
         cin.ignore(256, '\n');*/
        bool res = my_desion1.Start(inp, &result);
        if (!res)
        {
            result._expression += " 忽略，没有决策!\n";
        }
        else {
            result._expression += " 决策成功!\n";
        }
        std::string str = result.Serialize();
        file << "机器人1号:";
        file << "第 " << i++ << " 次：" << str << endl;
        //Sleep(1000);
    }

    file << "##############################################################" << endl;
    file << "######################非友好状态##############################" << endl;
    file << "##############################################################" << endl;

    i = 1;
    //经过10个人的共计10*200次的非友好交互后的机器人与新的交互者进行握手动作
    while (i <= 100)
    {

        Response result;
        RobotDec::Input inp;
        inp._name = j+1 ;
        inp._voice = 12;
        inp._pose = 0;
        /* cin >> inp._name >> inp._voice >> inp._pose;
         cin.ignore(256, '\n');*/
        bool res = my_desion2.Start(inp, &result);
        if (!res)
        {
            result._expression += " 忽略，没有决策!\n";
        }
        else {
            result._expression += " 决策成功!\n";
        }
        std::string str = result.Serialize();
        file << "机器人2号:";
        file << "第 " << i++ << " 次：" << str << endl;
        //Sleep(1000);
    }
    file << "与新人物交互实验时个性" << endl;
    file << "机器人1号对每个交互者的个性：" << endl;
    for (auto& e : my_desion1._identitys)
    {
        file << "身份：" << e.second._name << " 个性：" << e.second._mode << " " << endl;
    }
    file << "机器人2号对每个交互者的个性：" << endl;
    for (auto& e : my_desion2._identitys)
    {
        file << "身份：" << e.second._name << " 个性：" << e.second._mode << " " << endl;
    }

    bool res3 = my_desion1.Start(inp, &result);
    bool res4 = my_desion2.Start(inp, &result);
    file << endl;
    file << "与新人物交互实验后个性" << endl;
    file << "机器人1号对每个交互者的个性：" << endl;
    for (auto& e : my_desion1._identitys)
    {
        file << "身份：" << e.second._name << " 个性：" << e.second._mode << " " << endl;
    }
    file << "机器人2号对每个交互者的个性：" << endl;
    for (auto& e : my_desion2._identitys)
    {
        file << "身份：" << e.second._name << " 个性：" << e.second._mode << " " << endl;
    }
    file.close();
}
void test817()
{
    fstream file;
    file.open("per_test_817.txt", ios::app);
    file << "实验结果如下：" << endl;
    RobotDec::Desion my_desion1;//友好交互
    RobotDec::Desion my_desion2;//非友好交互
    file << "------------------" << endl << endl;
    int j = 0;
    bool flag1 = false;
    bool flag2 = false;
    while (j <20)
    {
        int i = 1;
        //第一个人的记忆交互
        file << "-------------身份：" << j + 1 << "-------------" << endl;
        file << "-------------------------------------------" << endl;
        if (j <10)
        {

            while (i <= 200)
            {
                Response result;
                RobotDec::Input inp;
                inp._name = j + 1;
                inp._voice = 11;//碰拳
                //if (flag1)
                //{
                //    inp._voice = 13;
                //    flag1 = false;
                //}
                inp._pose = 0;
                /* cin >> inp._name >> inp._voice >> inp._pose;
                 cin.ignore(256, '\n');*/
                bool res = my_desion1.Start(inp, &result);
                if (!res)
                {
                    result._expression += " 忽略，没有决策!";
                }
                else {
                    result._expression += " 决策成功!";
                }
                //if (result._mode == 17)
                //{
                //    flag1 = true;
                //}
                std::string str = result.Serialize();
                file << "机器人1号:";
                file << "第 " << i++ << " 次：" << str << endl;
                //Sleep(1000);
            }
        }
        else
        {
            while (i <= 200)
            {
                Response result;
                RobotDec::Input inp;
                inp._name = j + 1;
                inp._voice = 0;
                inp._pose = 12; //激怒
                /* cin >> inp._name >> inp._voice >> inp._pose;
                 cin.ignore(256, '\n');*/
                bool res = my_desion2.Start(inp, &result);
                if (!res)
                {
                    result._expression += " 忽略，没有决策!";
                }
                else {
                    result._expression += " 决策成功!";
                }
                std::string str = result.Serialize();
                file << "机器人2号:";
                file << "第 " << i++ << " 次：" << str << endl;
                //Sleep(1000);
            }
        }
        j++;
    }
    Response result;
    RobotDec::Input inp;
    inp._name = 255;
    bool res1 = my_desion1.Start(inp, &result);
    bool res2 = my_desion2.Start(inp, &result);

    file << "机器人1号对每个交互者的个性：" << endl;
    for (auto& e : my_desion1._identitys)
    {
        file << "身份：" << e.second._name << " 个性：" << e.second._mode << " " << endl;
    }
    file << "机器人2号对每个交互者的个性：" << endl;
    for (auto& e : my_desion2._identitys)
    {
        file << "身份：" << e.second._name << " 个性：" << e.second._mode << " " << endl;
    }

    file << "##############################################################" << endl;
    file << "######################友好状态################################" << endl;
    file << "##############################################################" << endl;
    int i = 1;
    //经过10个人的共计10*200次的友好交互后的机器人与新的交互者进行握手动作
    while (i <= 150)
    {

        Response result;
        RobotDec::Input inp;
        inp._name = j + 1;
        inp._voice = 12;//握手
        inp._pose = 0;
        /* cin >> inp._name >> inp._voice >> inp._pose;
         cin.ignore(256, '\n');*/
        bool res = my_desion1.Start(inp, &result);
        if (!res)
        {
            result._expression += " 忽略，没有决策!\n";
        }
        else {
            result._expression += " 决策成功!\n";
        }
        std::string str = result.Serialize();
        file << "机器人1号:";
        file << "第 " << i++ << " 次：" << str << endl;
        //Sleep(1000);
    }

    file << "##############################################################" << endl;
    file << "######################非友好状态##############################" << endl;
    file << "##############################################################" << endl;

    i = 1;
    //经过10个人的共计10*200次的非友好交互后的机器人与新的交互者进行握手动作
    while (i <= 150)
    {

        Response result;
        RobotDec::Input inp;
        inp._name = j + 1;
        inp._voice = 12;
        inp._pose = 0;
        /* cin >> inp._name >> inp._voice >> inp._pose;
         cin.ignore(256, '\n');*/
        bool res = my_desion2.Start(inp, &result);
        if (!res)
        {
            result._expression += " 忽略，没有决策!\n";
        }
        else {
            result._expression += " 决策成功!\n";
        }
        std::string str = result.Serialize();
        file << "机器人2号:";
        file << "第 " << i++ << " 次：" << str << endl;
        //Sleep(1000);
    }
    file << "与新人物交互实验时个性" << endl;
    file << "机器人1号对每个交互者的个性：" << endl;
    for (auto& e : my_desion1._identitys)
    {
        file << "身份：" << e.second._name << " 个性：" << e.second._mode << " " << endl;
    }
    file << "机器人2号对每个交互者的个性：" << endl;
    for (auto& e : my_desion2._identitys)
    {
        file << "身份：" << e.second._name << " 个性：" << e.second._mode << " " << endl;
    }

    bool res3 = my_desion1.Start(inp, &result);
    bool res4 = my_desion2.Start(inp, &result);
    file << endl;
    file << "与新人物交互实验后个性" << endl;
    file << "机器人1号对每个交互者的个性：" << endl;
    for (auto& e : my_desion1._identitys)
    {
        file << "身份：" << e.second._name << " 个性：" << e.second._mode << " " << endl;
    }
    file << "机器人2号对每个交互者的个性：" << endl;
    for (auto& e : my_desion2._identitys)
    {
        file << "身份：" << e.second._name << " 个性：" << e.second._mode << " " << endl;
    }
    file.close();
}

void test823()
{
    fstream file;
    file.open("per_test_823.txt", ios::app);
    file << "实验结果如下：" << endl;
    RobotDec::Desion my_desion1;//友好交互
    RobotDec::Desion my_desion2;//非友好交互
    file << "------------------" << endl << endl;
    int j = 0;
    bool flag1 = false;
    bool flag2 = false;
    while (j < 20)
    {
        int i = 1;
        //第一个人的记忆交互
       /* file << "-------------身份：" << j + 1 << "-------------" << endl;
        file << "-------------------------------------------" << endl;*/
        if (j < 10)
        {

            while (i <= 200)
            {
                Response result;
                RobotDec::Input inp;
                inp._name = j + 1;
                inp._voice = 11;//碰拳
                //if (flag1)
                //{
                //    inp._voice = 13;
                //    flag1 = false;
                //}
                inp._pose = 0;
                /* cin >> inp._name >> inp._voice >> inp._pose;
                 cin.ignore(256, '\n');*/
                bool res = my_desion1.Start(inp, &result);
                if (!res)
                {
                    result._expression += " 忽略，没有决策!";
                }
                else {
                    result._expression += " 决策成功!";
                }
                //if (result._mode == 17)
                //{
                //    flag1 = true;
                //}
                std::string str = result.Serialize();
                /*file << "机器人1号:";
                file << "第 " << i++ << " 次：" << str << endl;*/
                //Sleep(1000);
                i++;
            }
        }
        else
        {
            while (i <= 200)
            {
                Response result;
                RobotDec::Input inp;
                inp._name = j + 1;
                inp._voice = 0;
                inp._pose = 12; //激怒
                /* cin >> inp._name >> inp._voice >> inp._pose;
                 cin.ignore(256, '\n');*/
                bool res = my_desion2.Start(inp, &result);
                if (!res)
                {
                    result._expression += " 忽略，没有决策!";
                }
                else {
                    result._expression += " 决策成功!";
                }
                std::string str = result.Serialize();
               /* file << "机器人2号:";
                file << "第 " << i++ << " 次：" << str << endl;*/
                //Sleep(1000);
                i++;
            }
        }
        j++;
    }
    Response result;
    RobotDec::Input inp;
    inp._name = 255;
    bool res1 = my_desion1.Start(inp, &result);
    bool res2 = my_desion2.Start(inp, &result);

    file << "机器人1号对每个交互者的个性：" << endl;
    for (auto& e : my_desion1._identitys)
    {
        file << "身份：" << e.second._name << " 个性：" << e.second._mode << " " << endl;
    }
    file << "机器人2号对每个交互者的个性：" << endl;
    for (auto& e : my_desion2._identitys)
    {
        file << "身份：" << e.second._name << " 个性：" << e.second._mode << " " << endl;
    }

    file << "##############################################################" << endl;
    file << "######################友好状态################################" << endl;
    file << "##############################################################" << endl;
  
    //经过10个人的共计10*200次的友好交互后的机器人与新的交互者进行握手动作
    int k = 1;
    while (k <= 3)
    {
        file << "------第" << k <<"次交互------"<< endl;
        int i = 1;
        while (i <= 150)
        {

            Response result;
            RobotDec::Input inp;
            inp._name = j + k;
            if (k == 1)
            {
                inp._voice = 12;//握手
                inp._pose = 0;
            }
            else if (k == 2)
            {
                inp._voice = 0;
                inp._pose = 10;//鄙视
            }
            else
            {
                inp._voice = 9;//打招呼
                inp._pose = 6;//打招呼
            }
            /* cin >> inp._name >> inp._voice >> inp._pose;
             cin.ignore(256, '\n');*/
            bool res = my_desion1.Start(inp, &result);
            if (!res)
            {
                result._expression += " 忽略，没有决策!\n";
            }
            else {
                result._expression += " 决策成功!\n";
            }
            std::string str = result.Serialize();
            file << "机器人1号:";
            file << "第 " << i++ << " 次：" << str << endl;
            //Sleep(1000);
        }
        k++;
    }

    file << "##############################################################" << endl;
    file << "######################非友好状态##############################" << endl;
    file << "##############################################################" << endl;

    k = 1;
    //经过10个人的共计10*200次的非友好交互后的机器人与新的交互者进行握手动作
    while (k <= 3)
    {
        file << "------第" << k << "次交互------" << endl;
        int i = 1;
        while (i <= 150)
        {
            Response result;
            RobotDec::Input inp;
            inp._name = j + k;
            if (k == 1)
            {
                inp._voice = 12;//握手
                inp._pose = 0;
            }
            else if (k == 2)
            {
                inp._voice = 0;
                inp._pose = 10;//鄙视
            }
            else
            {
                inp._voice = 9;//打招呼
                inp._pose = 6;//打招呼
            }
            /* cin >> inp._name >> inp._voice >> inp._pose;
             cin.ignore(256, '\n');*/
            bool res = my_desion2.Start(inp, &result);
            if (!res)
            {
                result._expression += " 忽略，没有决策!\n";
            }
            else {
                result._expression += " 决策成功!\n";
            }
            std::string str = result.Serialize();
            file << "机器人2号:";
            file << "第 " << i++ << " 次：" << str << endl;
            //Sleep(1000);
        }
        k++;
    }
    file << "与新人物交互实验时个性" << endl;
    file << "机器人1号对每个交互者的个性：" << endl;
    for (auto& e : my_desion1._identitys)
    {
        file << "身份：" << e.second._name << " 个性：" << e.second._mode << " " << endl;
    }
    file << "机器人2号对每个交互者的个性：" << endl;
    for (auto& e : my_desion2._identitys)
    {
        file << "身份：" << e.second._name << " 个性：" << e.second._mode << " " << endl;
    }

    bool res3 = my_desion1.Start(inp, &result);
    bool res4 = my_desion2.Start(inp, &result);
    file << endl;
    file << "与新人物交互实验后个性" << endl;
    file << "机器人1号对每个交互者的个性：" << endl;
    for (auto& e : my_desion1._identitys)
    {
        file << "身份：" << e.second._name << " 个性：" << e.second._mode << " " << endl;
    }
    file << "机器人2号对每个交互者的个性：" << endl;
    for (auto& e : my_desion2._identitys)
    {
        file << "身份：" << e.second._name << " 个性：" << e.second._mode << " " << endl;
    }
    file.close();
}
void test829()
{
    fstream file;
    file.open("per_test_829.txt", ios::app);
    fstream file_data;
    file_data.open("per_data_829.txt", ios::app);

    file << "实验结果如下：" << endl;
    RobotDec::Desion my_desion1;//友好交互
    RobotDec::Desion my_desion2;//非友好交互
    file << "---------------------------------------------------------------------------------------------------" << endl<<endl;
    file_data << "----------------------------------------------------------------------------------------------------------------------------" << endl;
    file_data << "| 轮次 | 身份 | 次数 | 命令 | 手势 | 动作 | 表情 | 是否决策 | 模式 | 阶段 | 是否执行 | 态度 | 几率 |" << endl;
    file_data << "----------------------------------------------------------------------------------------------------------------------------" << endl;

    bool flag1 = false;
    bool flag2 = false;
    int k = 0;
    vector<pair<int, int>> r1 = { {0,1},{12,0},{15,7},{0,7},{0,10} };
    vector<pair<int, int>> r2 = { {8,0},{0,10},{0,12},{0,8},{12,0} };
    while (k < 2)
    {
        file << "---------------------------轮次" << k+1<< " ----------------------------------------------" << endl;
        file << "---------------------------------------------------------------------------------------------------" << endl<<endl;
        k++;
        int j = 1;
        while (j <= 30)
        {
            int i = 1;
            //第一个人的记忆交互
            file << "----------------------------------身份:" << j<< " -------------------------------------" << endl;
            file << "---------------------------------------------------------------------------------------" << endl;
            if (j %2==0)
            {
                i = 1;
                while (i <= 200)
                {
                    Response result;
                    RobotDec::Input inp;
                    inp._name = j;
                    int dex = RangProbability(0, 4);
                    inp._voice = r1[dex].first;
                    inp._pose = r1[dex].second;
                    bool res = my_desion1.Start(inp, &result);
                    if (!res)
                    {
                        result._expression += " 忽略，没有决策!";
                    }
                    else {
                        result._expression += " 决策成功!";
                    }
                    std::string str = result.Serialize();
                    file << "机器人1号:";
                    file << "第 " << i << " 次 -> 语音:" << VOICE[inp._voice] << " 手势:" << POSE[inp._pose] << " 结果:" << str << endl;
                    string out;
                    if (res)
                        out = "是";
                    else
                        out = "否";
                    if (result._res == 30)
                        result._res = 16;
                    file_data << k << "  " << j << "  " << i << "  " << VOICE[inp._voice] << "  " << POSE[inp._pose] << "  " << ACTION[result._mode % 23] << "  " << EMO[result._res % 17] << "  " <<out<< "  " <<result._data<< endl;
                    i++;//Sleep(1000);
                }
            }
            else
            {
                i = 1;
                while (i <= 200)
                {
                    Response result;
                    RobotDec::Input inp;
                    inp._name = j ;
                    int dex = RangProbability(0, 4);
                    inp._voice = r2[dex].first;
                    inp._pose = r2[dex].second;
                    bool res = my_desion2.Start(inp, &result);
                    if (!res)
                    {
                        result._expression += " 忽略，没有决策!";
                    }
                    else {
                        result._expression += " 决策成功!";
                    }
                    string out;
                    if (res)
                        out = "是";
                    else
                        out = "否";
                    std::string str = result.Serialize();
                    if (result._res == 30)
                        result._res = 16;
                    file << "第 " << i << " 次 -> 语音:" << VOICE[inp._voice] << " 手势:" << POSE[inp._pose] << " 结果:" << str << endl;
                    file_data << k << "  " << j << "  " << i << "  " << VOICE[inp._voice] << "  " << POSE[inp._pose] << "  " << ACTION[result._mode%23] << "  " << EMO[result._res%17] << "  " << out << "  " << result._data << endl;

                    i++;
                     //Sleep(1000);
                }
            }
            j++;
        }
        Response result;
        RobotDec::Input inp;
        inp._name = 255;
        bool res1 = my_desion1.Start(inp, &result);
        bool res2 = my_desion2.Start(inp, &result);
        if (k == 2)
            break;
        file.flush();
        file_data.flush();
        Sleep(1000 * 60 * 10);//一轮交互完成后等待10分钟
    }

    Response result;
    RobotDec::Input inp;
    inp._name = 255;
    bool res1 = my_desion1.Start(inp, &result);
    bool res2 = my_desion2.Start(inp, &result);
    file << "---------------------------------------------------------------------------------------------------"<<endl;
    file << "---------------------------------------------------------------------------------------------------" << endl;
    file << "---------------------------------------------------------------------------------------------------" << endl;


    file << "机器人1号对每个交互者的个性：" << endl;
    for (auto& e : my_desion1._identitys)
    {
        file << "身份：" << e.second._name << " 个性：" << e.second._mode << " " << endl;
    }
    file << "机器人2号对每个交互者的个性：" << endl;
    for (auto& e : my_desion2._identitys)
    {
        file << "身份：" << e.second._name << " 个性：" << e.second._mode << " " << endl;
    }

    file << "##############################################################" << endl;
    file << "##################机器人1，2同时进行新交互####################" << endl;
    file << "##############################################################" << endl;

    vector<pair<int, int>> r3 = { {0,7},{0,10},{0,12},{0,8},{12,0},{0,1} };

    file_data << "----------------------------------------------------------------------------------------------------------------------------" << endl;
    file_data << "| 编号 | 身份 | 次数 | 命令 | 手势 | 动作 | 表情 | 是否决策 | 模式 | 阶段 | 态度 | 是否执行 | 几率 |" << endl;
    file_data << "----------------------------------------------------------------------------------------------------------------------------" << endl;

    k = 1;
    int j = 50;
    while (k <= 5)
    {
        file << "------第" << k << "个人交互------" << endl;
        int i = 1;
        while (i <= 200)
        {

            Response result1;
            Response result2;

            RobotDec::Input inp;
            inp._name = j+k;
            int dex = RangProbability(0, 5);
            inp._voice = r3[dex].first;
            inp._pose = r3[dex].second;
            bool res1 = my_desion1.Start(inp, &result1);
            if (!res1)
            {
                result1._expression += " 忽略，没有决策!\n";
            }
            else {
                result1._expression += " 决策成功!\n";
            }
            bool res2 = my_desion2.Start(inp, &result2);
            if (!res2)
            {
                result2._expression += " 忽略，没有决策!\n";
            }
            else {
                result2._expression += " 决策成功!\n";
            }
            std::string str1 = result1.Serialize();
            if (result1._res == 30)
                result1._res = 16;
            if (result2._res == 30)
                result2._res = 16;
            file << "机器人1号:";
            file << "第 " << i << " 次 -> 语音:" << VOICE[inp._voice] << " 手势:" << POSE[inp._pose] << " 结果:" << str1 << endl;
            file_data << 1 << "  " << j+k << "  " << i << "  " << VOICE[inp._voice] << "  " << POSE[inp._pose] << "  " << ACTION[result1._mode % 23] << "  " << EMO[result1._res % 17] <<"  " << res1 << "  " << result1._data << endl;

            i++;//Sleep(1000);
               
            std::string str2 = result2.Serialize();
            file << "机器人2号:";
            file << "第 " << i << " 次 -> 语音:" << VOICE[inp._voice] << " 手势:" << POSE[inp._pose] << " 结果:" << str2 << endl

                << "-----------------------------------------------------------------------------------------------------------" << endl;
            file_data << 2 << "  " << j + k << "  " << i << "  " << VOICE[inp._voice] << "  " << POSE[inp._pose] << "  " << ACTION[result2._mode % 23] << "  " << EMO[result2._res % 17] << "  " << res2 << "  " << result2._data << endl;

            //Sleep(1000);
            i++;
        }
        Response result;
        RobotDec::Input inp;
        inp._name = 255;
        bool res1 = my_desion1.Start(inp, &result);
        bool res2 = my_desion2.Start(inp, &result);
        file.flush();
        file_data.flush();
        Sleep(1000 * 60 * 10);//每个新人物交互后等待10分钟
        k++;
    }

    file << endl << "---------------------------------------------------------------------------------------------------" << endl;
    file << "---------------------------------------------------------------------------------------------------" << endl;
    file << "---------------------------------------------------------------------------------------------------" << endl;
    bool res3 = my_desion1.Start(inp, &result);
    bool res4 = my_desion2.Start(inp, &result);
    file << endl;
    file << "与新人物交互实验后个性" << endl;
    file << "机器人1号对每个交互者的个性：" << endl;
    for (auto& e : my_desion1._identitys)
    {
        file << "身份：" << e.second._name << " 个性：" << e.second._mode << " " << endl;
    }
    file << "机器人2号对每个交互者的个性：" << endl;
    for (auto& e : my_desion2._identitys)
    {
        file << "身份：" << e.second._name << " 个性：" << e.second._mode << " " << endl;
    }
    file.close();
    file_data.close();
}
void test918()
{
    fstream file;
    file.open("per_test_918.txt", ios::app);
    fstream file_data;
    file_data.open("per_data_918.txt", ios::app);

    file << "实验结果如下：" << endl;
    RobotDec::Desion my_desion1;//友好交互
    RobotDec::Desion my_desion2;//非友好交互
    file << "---------------------------------------------------------------------------------------------------" << endl << endl;
    file_data << "----------------------------------------------------------------------------------------------------------------------------" << endl;
    file_data << "| 轮次 | 身份 | 次数 | 命令 | 手势 | 动作 | 表情 | 是否决策 | 模式 | 阶段 | 是否执行 | 态度 | 几率 |" << endl;
    file_data << "----------------------------------------------------------------------------------------------------------------------------" << endl;

    bool flag1 = false;
    bool flag2 = false;
    int k = 0;
 
    vector<pair<int, int>> r1 = { {0,1},{12,0},{7,15},{0,7},{0,10} };
    vector<pair<int, int>> r2 = { {8,0},{0,10},{0,12},{0,8},{12,0} };
    while (k < 2)
    {
        file << "---------------------------轮次" << k + 1 << " ----------------------------------------------" << endl;
        file << "---------------------------------------------------------------------------------------------------" << endl << endl;
        k++;
        int j = 1;
        while (j <= 30)
        {
            int i = 1;
            //第一个人的记忆交互
            //file << "----------------------------------身份:" << j << " -------------------------------------" << endl;
            //file << "---------------------------------------------------------------------------------------" << endl;
            if (j % 2 == 0)
            {
                i = 1;
                while (i <= 300)
                {
                    Response result;
                    RobotDec::Input inp;
                    inp._name = j;
                    int dex = RangProbability(0, 4);
                    inp._voice = r1[dex].first;
                    inp._pose = r1[dex].second;
                    bool res = my_desion1.Start(inp, &result);
                    if (!res)
                    {
                        result._expression += " 忽略，没有决策!";
                    }
                    else {
                        result._expression += " 决策成功!";
                    }
                    std::string str = result.Serialize();
                   file << "机器人1号:";
                   file << "第 " << i << " 次 -> 语音:" << VOICE[inp._voice] << " 手势:" << POSE[inp._pose] << " 结果:" << str << endl;
                    string out;
                    if (res)
                        out = "是";
                    else
                        out = "否";
                    if (result._res == 30)
                        result._res = 16;
                    file_data << k << "  " << j << "  " << i << "  " << VOICE[inp._voice] << "  " << POSE[inp._pose] << "  " << ACTION[result._mode % 23] << "  " << EMO[result._res % 17] << "  " << out << "  " << result._data << endl;
                    i++;//Sleep(1000);
                }
            }
            else
            {
                i = 1;
                while (i <= 200)
                {
                    Response result;
                    RobotDec::Input inp;
                    inp._name = j;
                    int dex = RangProbability(0, 4);
                    inp._voice = r2[dex].first;
                    inp._pose = r2[dex].second;
                    bool res = my_desion2.Start(inp, &result);
                    if (!res)
                    {
                        result._expression += " 忽略，没有决策!";
                    }
                    else {
                        result._expression += " 决策成功!";
                    }
                    string out;
                    if (res)
                        out = "是";
                    else
                        out = "否";
                    std::string str = result.Serialize();
                    if (result._res == 30)
                        result._res = 16;
                   file << "机器人2号:";
                   file << "第 " << i << " 次 -> 语音:" << VOICE[inp._voice] << " 手势:" << POSE[inp._pose] << " 结果:" << str << endl;
                   file_data << k << "  " << j << "  " << i << "  " << VOICE[inp._voice] << "  " << POSE[inp._pose] << "  " << ACTION[result._mode % 23] << "  " << EMO[result._res % 17] << "  " << out << "  " << result._data << endl;

                    i++;
                    //Sleep(1000);
                }
            }
            j++;
            //每个人物交互后等待10分钟
            Sleep(1000 * 60 * 10);
        }
        Response result;
        RobotDec::Input inp;
        inp._name = 255;
        bool res1 = my_desion1.Start(inp, &result);
        bool res2 = my_desion2.Start(inp, &result);
        if (k == 2)
            break;
        file.flush();
        file_data.flush();
        Sleep(1000 * 60 * 10);//一轮交互完成后等待10分钟
    }

    Response result;
    RobotDec::Input inp;
    inp._name = 255;
    bool res1 = my_desion1.Start(inp, &result);
    bool res2 = my_desion2.Start(inp, &result);
    file << "---------------------------------------------------------------------------------------------------" << endl;
    file << "---------------------------------------------------------------------------------------------------" << endl;
    file << "---------------------------------------------------------------------------------------------------" << endl;


    file << "机器人1号对每个交互者的个性：" << endl;
    for (auto& e : my_desion1._identitys)
    {
        file << "身份：" << e.second._name << " 个性：" << e.second._mode << " " << endl;
    }
    file << "机器人2号对每个交互者的个性：" << endl;
    for (auto& e : my_desion2._identitys)
    {
        file << "身份：" << e.second._name << " 个性：" << e.second._mode << " " << endl;
    }

    file << "##############################################################" << endl;
    file << "##################机器人1，2同时进行新交互####################" << endl;
    file << "##############################################################" << endl;

    vector<pair<int, int>> r3 = { {0,7},{0,10},{0,12},{0,8},{12,0},{0,1} };

    //file_data << "----------------------------------------------------------------------------------------------------------------------------" << endl;
    file_data << "编号 身份 次数 命令 手势 动作 表情 是否决策 模式 阶段 态度 是否执行 几率 " << endl;
    //file_data << "----------------------------------------------------------------------------------------------------------------------------" << endl;

    k = 1;
    int j = 50;
    while (k <= 5)
    {
        file << "------第" << k << "个人交互------" << endl;
        int i = 1;
        while (i <= 200)
        {

            Response result1;
            Response result2;

            RobotDec::Input inp;
            inp._name = j + k;
            int dex = RangProbability(0, 5);
            inp._voice = r3[dex].first;
            inp._pose = r3[dex].second;
            bool res1 = my_desion1.Start(inp, &result1);
            if (!res1)
            {
                result1._expression += " 忽略，没有决策!\n";
            }
            else {
                result1._expression += " 决策成功!\n";
            }
            bool res2 = my_desion2.Start(inp, &result2);
            if (!res2)
            {
                result2._expression += " 忽略，没有决策!\n";
            }
            else {
                result2._expression += " 决策成功!\n";
            }
            std::string str1 = result1.Serialize();
            if (result1._res == 30)
                result1._res = 16;
            if (result2._res == 30)
                result2._res = 16;
            string out1;
            if (res1)
                out1 = "是";
            else
                out1 = "否";
            string out2;
            if (res2)
                out2 = "是";
            else
                out2 = "否";
            file << "机器人1号:";
            file << "第 " << i << " 次 -> 语音:" << VOICE[inp._voice] << " 手势:" << POSE[inp._pose] << " 结果:" << str1 << endl;
            file_data << 1 << "  " << j + k << "  " << i << "  " << VOICE[inp._voice] << "  " << POSE[inp._pose] << "  " << ACTION[result1._mode % 23] << "  " << EMO[result1._res % 17] << "  " << out1 << "  " << result1._data << endl;

            i++;//Sleep(1000);

            std::string str2 = result2.Serialize();
            file << "机器人2号:";
            file << "第 " << i << " 次 -> 语音:" << VOICE[inp._voice] << " 手势:" << POSE[inp._pose] << " 结果:" << str2 << endl

                << "-----------------------------------------------------------------------------------------------------------" << endl;
            file_data << 2 << "  " << j + k << "  " << i << "  " << VOICE[inp._voice] << "  " << POSE[inp._pose] << "  " << ACTION[result2._mode % 23] << "  " << EMO[result2._res % 17] << "  " << out2 << "  " << result2._data << endl;

            //Sleep(1000);
            i++;
        }
        Response result;
        RobotDec::Input inp;
        inp._name = 255;
        bool res1 = my_desion1.Start(inp, &result);
        bool res2 = my_desion2.Start(inp, &result);
        file.flush();
        file_data.flush();
        Sleep(1000 * 60 * 10);//每个新人物交互后等待10分钟
        k++;
    }

    file << endl << "---------------------------------------------------------------------------------------------------" << endl;
    file << "---------------------------------------------------------------------------------------------------" << endl;
    file << "---------------------------------------------------------------------------------------------------" << endl;
    bool res3 = my_desion1.Start(inp, &result);
    bool res4 = my_desion2.Start(inp, &result);
    file << endl;
    file << "与新人物交互实验后个性" << endl;
    file << "机器人1号对每个交互者的个性：" << endl;
    for (auto& e : my_desion1._identitys)
    {
        file << "身份：" << e.second._name << " 个性：" << e.second._mode << " " << endl;
    }
    file << "机器人2号对每个交互者的个性：" << endl;
    for (auto& e : my_desion2._identitys)
    {
        file << "身份：" << e.second._name << " 个性：" << e.second._mode << " " << endl;
    }
    file.close();
    file_data.close();
}
int main()
{
    //test817();
    //test6();
    //test4();
    //test823();
    test918();
    //int i = 0;
    //while (i < 20)
    //{
    //    int num = RangProbability(0, 4);
    //    cout << num << " ; " << endl;
    //    i++;
    //}
    //cout << X<5>::v;
    cout << "统计结束" << endl;
    return 0;
   
}